<%--
  Created by IntelliJ IDEA.
  User: 凡人
  Date: 2021/12/3
  Time: 14:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <!--视口 自适应-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>title</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.2.1.js" rel="script"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.js" rel="script"></script>
    <script src="${pageContext.request.contextPath}/static/My97DatePicker/WdatePicker.js" rel="script"></script>

</head>
<body>
<form action="" method="post">
    出库单号:<input type="text" name="oid" readonly="readonly" value="${o.id}">
    发货单号:<input type="text" name="id" readonly="readonly" value="${oDetail}">
    发货日期:<input type="text" name="sendDate" readonly="readonly" onclick="WdatePicker()"><br><br>
    制单人工号:<input type="text" name="preparedId" value="${user.id}">
    制单人:<input type="text" name="preparedBy" value="${user.username}${user.id}">
    制单时间:<input type="text" name="preparedDate" readonly="readonly" onclick="WdatePicker()"><br><br>
    发货地址:<input type="text" name="clientid">
    出库金额:<input type="text" name="sendid" value="${o.orderPrice}"><br><br>
    发货附件:<input type="file" name="file" onchange="upFile(this)" ><span></span>
    发货总金额:<input type="text" name="sendPrice">
    <div id="pic" style="color: red">
        <input type="text" name="iamge" value="${o.image}">
    </div><br><br>
    差额:<input type="text" name="agio">
    备注:<input type="text" name="content" value="${o.content}"><br><br>

    <input type="button" onclick="addCo()" value="添加">
    <table class="table">
        <thead>
        <tr>
            <th scope="col">物料编号</th>
            <th scope="col">物料名称</th>
            <th scope="col">销售单价</th>
            <th scope="col">数量</th>
            <th scope="col">金额</th>
            <th scope="col">收货地址</th>
            <th scope="col">是否收货</th>
            <th scope="col">备注</th>
            <th scope="col">联系人</th>
            <th scope="col">联系电话</th>
        </tr>
        </thead>
        <tbody id="tbody">
        <tr>
            <td><input type="text" name="lists[0].feedid"></td>
            <td><input type="text" name="lists[0].feed"></td>
            <td><input type="text" name="lists[0].price" onblur="js(0)"></td>
            <td><input type="text" name="lists[0].num" onblur="js(0)"></td>
            <td><input type="text" name="lists[0].money" class="sum"></td>
            <td><input type="text" name="lists[0].site"></td>
            <td><input type="text" name="lists[0].status"></td>
            <td><input type="text" name="lists[0].content"></td>
            <td><input type="text" name="lists[0].linkman"></td>
            <td><input type="text" name="lists[0].tel"></td>
        </tr>
        </tbody>
    </table>
    <input type="button" id="but" value="提交">
</form>
</body>
<script>
    //发货
    function shipping(){
        $.post("./addSend",$("form").serialize(),function(msg){
            if(msg=="ok"){
                $("#nav-tabContent").load("./toAdd");
            }
        })
    }
    //添加
    $("#but").click(function(){
        $.post("./toAdd",$("form").serialize(),function(msg){
            if(msg=="ok"){
                $("#nav-tabContent").load("./list");
            }
        })
    })

    //图片
    function upFile(obj){
        var formData = new FormData();
        formData.append("file",obj.files[0]);
        $.ajax({
            url:"upFile",
            data:formData,
            type:'post',
            contentType:false,
            processData:false,
            success:function(url){
                $("#pic").empty();
                if(url.code==200){
                    $("#pic").append("<input type='text' name='image' value='"+url.msg+"'>");
                }else{
                    $("#pic").text(url.msg);
                }
            }
        })
    }

    //添加行
    var i = 1;
    function addCo(){
        $("#tbody").append('<tr> ' +
            '<td><input type="text" name="lists['+i+'].feedid"></td> ' +
            '<td><input type="text" name="lists['+i+'].feed"></td> ' +
            '<td><input type="text" name="lists['+i+'].price" onblur="js('+i+')"></td> ' +
            '<td><input type="text" name="lists['+i+'].num" onblur="js('+i+')"></td> ' +
            '<td><input type="text" name="lists['+i+'].money" class="sum"></td> ' +
            '<td><input type="text" name="lists['+i+'].site"></td> ' +
            '<td><input type="text" name="lists['+i+'].status"></td> ' +
            '<td><input type="text" name="lists['+i+'].content"></td> ' +
            '<td><input type="text" name="lists['+i+'].linkman"></td> ' +
            '<td><input type="text" name="lists['+i+'].tel"></td> ' +
            '</tr>')
        i++;
    }
    function remCol(obj){
        $(obj).parent().parent().remove();
    }
    function js(i){
        var price = $("[name='lists["+i+"].price']").val();
        var num = $("[name='lists["+i+"].num']").val();
        if((price*num)!=0){
            $("[name='lists["+i+"].money']").val(Number(price)*Number(num));
        }
        sum();
    }
    function sum(){
        var s = 0;
        $(".sum").each(function(){
            s += Number($(this).val());
        })
        $('[name="sendPrice"]').val(s);
    }
</script>
</html>
